const db = function (success, error = function () { console.log('连接失败') }) {
    const mongoose = require("mongoose")
    const { DBHOST, DBPORT, DBNAME } = require("../config/config")
    mongoose.connect(`mongodb://${DBHOST}:${DBPORT}/${DBNAME}`)

    mongoose.connection.once('open', function () {
        console.log('连接成功')
        success()
    })

    mongoose.connection.on('error', function () {
        error()
    })

    mongoose.connection.on("close", function () {
        console.log("连接断开")
    })
}

module.exports = db